package com.champrin.replicationofmyblockapix.http;

import android.app.AlertDialog;
import android.provider.BaseColumns;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.champrin.replicationofmyblockapix.R;

public class Player {
    public static Player globolPlayer = null;

    public static class PlayerEntry implements BaseColumns {
        public static final String TABLE_NAME = "player_info";
        public static final String COLUMN_NAME_USERNAME = "username";
        public static final String COLUMN_NAME_GAME_TOTAL_CNT = "game_total_cnt";
        public static final String COLUMN_NAME_GAME_FINISH_TOTAL_CNT = "game_finish_total_cnt";
        public static final String COLUMN_NAME_AVER_FINISH_TIME = "aver_finish_time";
        public static final String COLUMN_NAME_REGISTER_TIME = "register_time";
    }

    private String username;
    private int game_total_cnt;
    private int game_finish_total_cnt;
    private float aver_finish_time;
    private String register_time;

    public Player(String username, int game_total_cnt, int game_finish_total_cnt, float aver_finish_time, String register_time) {
        this.username = username;
        this.game_total_cnt = game_total_cnt;
        this.game_finish_total_cnt = game_finish_total_cnt;
        this.aver_finish_time = aver_finish_time;
        this.register_time = register_time;
    }

    public String getUsername() {
        return username;
    }

    public int getGame_total_cnt() {
        return game_total_cnt;
    }

    public int getGame_finish_total_cnt() {
        return game_finish_total_cnt;
    }

    public float getAver_finish_time() {
        return aver_finish_time;
    }

    public String getRegister_time() {
        return register_time;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setGame_total_cnt(int game_total_cnt) {
        this.game_total_cnt = game_total_cnt;
    }

    public void setGame_finish_total_cnt(int game_finish_total_cnt) {
        this.game_finish_total_cnt = game_finish_total_cnt;
    }

    public void setAver_finish_time(float aver_finish_time) {
        this.aver_finish_time = aver_finish_time;
    }

    public void setRegister_time(String register_time) {
        this.register_time = register_time;
    }

    @Override
    public String toString() {
        return "Player{" +
                "username='" + username + '\'' +
                ", game_total_cnt=" + game_total_cnt +
                ", game_finish_total_cnt=" + game_finish_total_cnt +
                ", aver_finish_time=" + aver_finish_time +
                ", register_time='" + register_time + '\'' +
                '}';
    }

    public void showPlayerInfoDialog(AlertDialog.Builder dialogBuilder, LayoutInflater inflater) {
        View dialogView = inflater.inflate(R.layout.dialog_player_info_layout, null);
        dialogBuilder.setView(dialogView);

        TextView tvId = dialogView.findViewById(R.id.tv_id);
        TextView tvGameTotalCnt = dialogView.findViewById(R.id.tv_game_total_cnt);
        TextView tvGameFinishTotalCnt = dialogView.findViewById(R.id.tv_game_finish_total_cnt);
        TextView tvAverFinishTime = dialogView.findViewById(R.id.tv_aver_finish_time);
        TextView tvRegisterTime = dialogView.findViewById(R.id.tv_register_time);
        Button btnExit = dialogView.findViewById(R.id.btn_exit);

        // 设置用户角色信息
        tvId.setText("ID: " + username);
        tvGameTotalCnt.setText("总局数量:" + game_total_cnt);
        tvGameFinishTotalCnt.setText("完成数量:" + game_finish_total_cnt);
        tvAverFinishTime.setText("平均时长:" + aver_finish_time);
        tvRegisterTime.setText("注册时间:" + register_time);

        final AlertDialog dialog = dialogBuilder.create();
        // 设置AlertDialog的背景为透明
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

        btnExit.setOnClickListener(v -> dialog.dismiss());

        dialog.show();
    }

}
